/* eslint-disable space-before-function-paren */
/* eslint-disable indent */
/* eslint-disable eol-last */
let commonUtil = {}
commonUtil.createRandomCode = function(len) {
    var code = ''
        // 设置长度，这里看需求，我这里设置了4
    var codeLength = len || 6
        // 设置随机字符
        // eslint-disable-next-line no-array-constructor
    var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
        // 循环codeLength 我设置的4就是循环4次
    for (var i = 0; i < codeLength; i++) {
        // 设置随机数范围,这设置为0 ~ 36
        var index = Math.floor(Math.random() * 9)

        // 字符串拼接 将每次随机的字符 进行拼接
        code += random[index]
    }
    // 将拼接好的字符串赋值给展示的code
    return code
}
commonUtil.objSortWithProName = function(obj) {
    let pnames = Object.keys(obj).sort()
    let retobj = {}
    for (let i in pnames) {
        let name = pnames[i]
        retobj[name] = obj[name]
    }
    return retobj
}
commonUtil.stringFormat = function stringFormat(formatted, args) {
    for (let i = 0; i < args.length; i++) {
        let regexp = new RegExp('\\{' + i + '\\}', 'gi')
        formatted = formatted.replace(regexp, args[i])
    }
    return formatted
}
export default commonUtil